import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AroutUtil {
  static void goTo(BuildContext context, Widget widget) {
    // Navigator.push(context, MaterialPageRoute(builder: (context) {
    //   return widget;
    // }));
    // Navigator.push(
    //   context,
    //   PageRouteBuilder(
    //     transitionDuration: Duration(milliseconds: 500), //动画时间为500毫秒
    //     pageBuilder: (BuildContext context, Animation animation,
    //         Animation secondaryAnimation) {
    //       return new FadeTransition(
    //         //使用渐隐渐入过渡,
    //         opacity: animation,
    //         child: widget, //路由B
    //       );
    //     },
    //   ),
    // );
    /**
     * 跳转渐进式动画
     */
    Navigator.push(
      context,
      PageRouteBuilder(
          transitionDuration: const Duration(milliseconds: 500),
          pageBuilder: (BuildContext context, Animation<double> animation1,
              Animation<double> animation2) {
            return widget;
          },
          transitionsBuilder: (BuildContext context,
              Animation<double> animation1,
              Animation<double> animation2,
              Widget child) {
            return SlideTransition(
              position: Tween<Offset>(
                      //1.0为右进右出，-1.0为左进左出
                      begin: Offset(1.0, 0.0),
                      end: Offset(0.0, 0.0))
                  .animate(CurvedAnimation(
                      parent: animation1, curve: Curves.fastOutSlowIn)),
              child: child,
            );
          }),
    );
  }
}
